package org.takeback.chat.service.support.ord;

import java.util.Map;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
import org.takeback.chat.entity.Message;
import org.takeback.chat.lottery.listeners.GameException;
import org.takeback.chat.lottery.listeners.RoomAndLotteryListener;
import org.takeback.chat.store.room.Room;
import org.takeback.chat.store.user.User;
import org.takeback.chat.utils.MessageUtils;

@Component("handsUpCmd")
public class HandsUpCmd implements Command {

	@Override
	public void exec(Map data, Message message, WebSocketSession session, Room room, User user) {
        user.setHandsUp(true);

		RoomAndLotteryListener listener = room.getRoomAndLotteryListener();
		try {
			if (listener != null) {
				if (listener.onBeforeStart(room)) {
					room.start();
				}
			} else {
				room.start();
			}
		} catch (GameException e) {
			MessageUtils.sendCMD(session, "alert", e.getMessage());
		}
	}
}
